import os
from confg.products import products
from models.recommender import SnackRecommender
from utils.data_generator import (
    generate_user_ids,
    generate_timestamps,
    generate_recommendation_ticket
)
from utils.file_export import export_data, save_models


def main():
    print("初始化零食推荐系统...")

    # 创建输出目录
    output_dir = "recommendation_data"
    os.makedirs(output_dir, exist_ok=True)

    # 初始化推荐器
    recommender = SnackRecommender(products)
    print("模型训练完成")

    # 生成用户ID和时间序列
    user_ids = generate_user_ids(200)
    timestamps = generate_timestamps(200)

    print("生成推荐工单...")
    tickets = []
    for i, user_id in enumerate(user_ids):
        ticket = generate_recommendation_ticket(recommender, user_id, timestamps[i])
        tickets.append(ticket)

        if (i + 1) % 50 == 0:
            print(f"已生成 {i + 1} 个工单")

    # 导出数据
    print("导出数据...")
    export_data(tickets, products, output_dir)
    save_models(recommender, output_dir)


if __name__ == "__main__":
    main()